<?php

/*
 * group forum_info 
 * @author yangchao
 * @package group
 * @copyright yangchao
 * @version 1.2
 * @code-encode utf-8
 * @data-encode utf-8
*/

if (isset($_GET["test_db"]))
{
	include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
}

class db_forum_info extends db_base
{
	var $tbl_name = "forum_info";

	function db_forum_info()
	{
		parent::db_base();
	}

//前台程序开始	
	/**
	 * 前台显示单个数据
	 * @param int id
	 */
	function get_item_by_id($id)
	{       
		//验证传入参数
		$id = intval($id);
		if(!$id) throw new Exception("DB:id错误！");
		//如果id是字符串，并且在where条件中使用 ：$id = string::esc_mysql($id);
			 
		$data = false;
		$key = "cache 前缀 未定" . "-get_item_by_id-{$id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			//处理where条件
			$where = " id = {$id} and status = 1 " ;	
			$data = $this->get_alllist($this->tbl_name, 1, 1, "",$where);
			$mc->set($key, serialize($data), 0, "cachetime未定");
		}
		else
		{
			$data = unserialize($cache);
		}

		return $data[0];
	}	
	
		
	//添加一条数据
	function insert_forum_info(
		$current_uid,
		$f_name,
		$f_pic,
		$f_detail,
		$f_type,
		$f_display_order,
		$count_total_long,
		$count_total_short,
		$count_today_long,
		$count_today_short,
		$last_link,
		$last_title,
		$last_uid,
		$last_username
		
	)
	{
		global $config;
		//详细字段
		$ary = array();
		$ary["f_name"] = $f_name;
		$ary["f_pic"] = $f_pic;
		$ary["f_detail"] = $f_detail;
		$ary["f_type"] = $f_type;
		$ary["f_display_order"] = $f_display_order;
		$ary["count_total_long"] = $count_total_long;
		$ary["count_total_short"] = $count_total_short;
		$ary["count_today_long"] = $count_today_long;
		$ary["count_today_short"] = $count_today_short;
		$ary["last_link"] = $last_link;
		$ary["last_title"] = $last_title;
		$ary["last_uid"] = $last_uid;
		$ary["last_username"] = $last_username;
		
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->tbl_name, $ary);
		if ($ret)
		{
			$memcache = mem_cache::get_instance();
			$key[] = "need to delete";
			$memcache->delete_ary($key);
		}
		else
		{
			return false;
		}

		return $this->get_lastinsertid();
	}

	
	//修改一条数据
	function update_forum_info_by_id(
		$current_uid,
		$f_name,
		$f_pic,
		$f_detail,
		$f_type,
		$f_display_order,
		$count_total_long,
		$count_total_short,
		$count_today_long,
		$count_today_short,
		$last_link,
		$last_title,
		$last_uid,
		$last_username,
		$id
		
	)
	{
		global $config;

		//检查字段
		$id = intval($id);
		if(!$id) throw new Exception("DB:id有错误！");
		//如果id是字符串，并且在where条件中使用 ：$id = string::esc_mysql($id);
		
		//详细字段
		$ary = array();
		$ary["f_name"] = $f_name;
		$ary["f_pic"] = $f_pic;
		$ary["f_detail"] = $f_detail;
		$ary["f_type"] = $f_type;
		$ary["f_display_order"] = $f_display_order;
		$ary["count_total_long"] = $count_total_long;
		$ary["count_total_short"] = $count_total_short;
		$ary["count_today_long"] = $count_today_long;
		$ary["count_today_short"] = $count_today_short;
		$ary["last_link"] = $last_link;
		$ary["last_title"] = $last_title;
		$ary["last_uid"] = $last_uid;
		$ary["last_username"] = $last_username;
		
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
	
		$where = " id = $id and status = 1";
		$ret = $this->update($this->tbl_name, $ary,$where);
		if ($ret)
		{
			$memcache = mem_cache::get_instance();
			$key[] = "need to delete";
			$memcache->delete_ary($key);
		}
		else
		{
			return false;
		}


		return $ret;
	}
//前台程序结束
	

	
//后台程序开始	
	/**
	 * 后台取单个数据
	 * @param int id
	 */
	function admin_get_item_by_id($id)
	{       
		//验证传入参数
		$id = intval($id);
		if(!$id) throw new Exception("DB:id错误！");
		//如果$id是字符串，并且在where条件中使用 ：$id = string::esc_mysql($id);
		
		//处理where条件
		$where = " id = {$id} and status = 1 " ;	
		$data = $this->get_alllist($this->tbl_name, 1, 1, "",$where);
		
		return $data[0];
	}	
	
}


